import { prisma } from "@/lib/prisma"
import { OutboundList } from "@/components/outbound/outbound-list"
import { OutboundHeader } from "@/components/outbound/outbound-header"
import { Metadata } from "next"

export const metadata: Metadata = {
  title: "出库管理 - 商场销售系统",
  description: "出库管理页面",
}

export default async function OutboundPage() {
  const sales = await prisma.sale.findMany({
    orderBy: {
      createdAt: 'desc'
    },
    include: {
      items: {
        include: {
          product: true
        }
      }
    }
  })

  // 序列化数据
  const serializedSales = sales.map(sale => ({
    ...sale,
    totalAmount: sale.totalAmount.toString(),
    createdAt: sale.createdAt.toISOString(),
    updatedAt: sale.updatedAt.toISOString(),
    items: sale.items.map(item => ({
      ...item,
      price: item.price.toString(),
      amount: item.amount.toString(),
      product: {
        ...item.product,
        price: item.product.price.toString()
      }
    }))
  }))

  return (
    <div className="space-y-4 p-8">
      <OutboundHeader />
      <OutboundList sales={serializedSales} />
    </div>
  )
} 